<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<link rel="STYLESHEET" type="text/css" href="${base}/res/admin/css/tab.css"/>
	<script type="text/javascript" src="${base}/res/comm/js/jquery/jquery.js"></script>
	<script type="text/javascript" src="${base}/res/admin/js/admin.js"></script>
	<script type="text/javascript" src="${base}/res/comm/js/kindeditor/kindeditor-min.js"></script>
	<script type="text/javascript" src="${base}/res/comm/js/kindeditor/lang/zh_CN.js"></script>
	<script lang="javascript">
	var MyKE;
	var goodsbrief_editor,goodsabout_editor;
		function save(){
			if($('#goodsname').val().trim() == ''){
				window.alert('商品名称不能为空');
				$('#goodsname').select();
			}
			
			var imgs = '';
			$('input[name=imgs]').each(function(i){
				imgs += $(this).val()+';';
			});
			if(imgs.endWith(';'))
				imgs = imgs.substring(0,imgs.length-1);
			goodsbrief_editor.sync();
			goodsabout_editor.sync();
			ajaxPost('${base}/admin/goods/save.jhtml',
				{
				'id':$('#id').val(),
				'cid':$('#cid').val(),
				'goodsname':$('#goodsname').val(),
				'goodsfreight':$('#goodsfreight').val(),
				'goodsbrief':$('#goodsbrief').val(),
				'goodsabout':$('#goodsabout').val(),
				'imgs':imgs
				},null,'json',savecallback);
		}
		function savecallback(data){
			window.alert(data.message);
			if(data.status=='success'){
				window.location.href='${base}/admin/goods/index.jhtml';	
			}
		}
		
		function delself(imgid){
			ajaxPost('${base}/admin/accessory/delete.jhtml',{'id':imgid},null,'json',
				function(data){
					window.alert(data.message);
					if(data.status=='success'){
						var divid = $("#div_"+imgid);
						divid.remove();
					}
				});
		}
		
		KindEditor.ready(function(K) {
				MyKE = K;
				goodsbrief_editor = K.create('#goodsbrief', {
					items : [
						'source','fontname', 'fontsize', '|', 'forecolor', 'hilitecolor', 'bold', 'italic', 'underline',
						'removeformat', '|', 'justifyleft', 'justifycenter', 'justifyright', 'insertorderedlist',
						'insertunorderedlist', '|', 'emoticons', 'image', 'link']
				});
				goodsabout_editor = K.create('#goodsabout', {
					items : [
						'source','fontname', 'fontsize', '|', 'forecolor', 'hilitecolor', 'bold', 'italic', 'underline',
						'removeformat', '|', 'justifyleft', 'justifycenter', 'justifyright', 'insertorderedlist',
						'insertunorderedlist', '|', 'emoticons', 'image', 'link']
				});
				var uploadbutton = K.uploadbutton({
					button : K('#uploadButton')[0],
					fieldName : 'imgFile',
					url : '${base}/admin/accessory/upload.jhtml',
					afterUpload : function(data) {
						if (data.status == 'success') {
							$('<div id="div_'+data.id+'" style="width: 115px; float: left; text-align: center;"><img src="'+data.saveURL+'" width="72" height="72" style="margin: 5px; vertical-align: middle; opacity: 1;"><br><a href="javascript:delself('+data.id+');">删除</a><input type="hidden" value="'+data.id+'" name="imgs"></div>').appendTo('#thumbnails');
						} else {
							alert(data.message);
						}
					},
					afterError : function(str) {
						alert('自定义错误信息: ' + str);
					}
				});
				uploadbutton.fileBox.change(function(e) {
					uploadbutton.submit();
				});
			});
	</script>
  </head>
  
<body style="overflow:auto;">
<table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
	  <tr>
	    <td height="30">
	    <table width="100%" border="0" cellspacing="0" cellpadding="0">
	      <tr>
	        <td width="15" height="30"><img src="${base}/res/admin/images/tab_03.gif" width="15" height="30" /></td>
	        <td background="${base}/res/admin/images/tab_05.gif"><img src="${base}/res/admin/images/311.gif" width="16" height="16" /> <span class="STYLE4" style="16">添加/编辑商品分类</span></td>
	        <td width="14"><img src="${base}/res/admin/images/tab_07.gif" width="14" height="30" /></td>
	      </tr>
	    </table>
	    </td>
	  </tr>
	  <tr>
	    <td>
	    <table width="100%" border="0" cellspacing="0" cellpadding="0">
	      <tr>
	        <td width="9" background="${base}/res/admin/images/tab_12.gif">&nbsp;</td>
	        <td bgcolor="#e5f1d6">
	        <table width="100%">
	    		<tr>
	    			<td widith="50%">
	        <input type="hidden" id="id" name="id" value="${(goods.id)!"0"}">
	        <table width="99%" border="0" align="center" cellpadding="4" cellspacing="0" bgcolor="#CECECE">
    		<tr>
		   		<td height="18" bgcolor="#FFFFFF"><span class="STYLE1">商品名称:</span></td>
		   		<td height="18" bgcolor="#FFFFFF"><input id="goodsname" name="goodsname" value="${(goods.goodsname)!""}"  style="width:700px;"/></td>
		  		<td width="10%"  bgcolor="#FFFFFF">&nbsp;</td>
		  	</tr>
		  	<tr>
		   		<td height="18" bgcolor="#FFFFFF"><span class="STYLE1">所属分类:</span></td>
		   		<td height="18" bgcolor="#FFFFFF">
		   		<select  style="width:700px;" id="cid" name="cid">
		   			<#list categoryList! as list>
		   			<option value="${list.id}">${list.categoryname}</option>
		   			</#list>
		   		</select>
		   		</td>
		  		<td width="10%"  bgcolor="#FFFFFF">&nbsp;</td>
		  	</tr>
		  	<tr>
		   		<td height="18" bgcolor="#FFFFFF"><span class="STYLE1">商品运费:</span></td>
		   		<td height="18" bgcolor="#FFFFFF"><input id="goodsfreight" name="goodsfreight" value="${(goods.goodsfreight)!""}" style="width:700px;"/></td>
		  		<td width="10%"  bgcolor="#FFFFFF">&nbsp;</td>
		  	</tr>
		  	<tr>
		   		<td height="18" bgcolor="#FFFFFF"><span class="STYLE1">商品简介:</span></td>
		   		<td height="18" bgcolor="#FFFFFF"><textarea id="goodsbrief" name="goodsbrief" style="width:700px;height:200px;visibility:hidden;">${(goods.goodsbrief)!""}</textarea></td>
		  		<td width="10%"  bgcolor="#FFFFFF">&nbsp;</td>
		  	</tr>
		  	<tr>
		   		<td height="18" bgcolor="#FFFFFF"><span class="STYLE1">商品描述:</span></td>
		   		<td height="18" bgcolor="#FFFFFF"><textarea id="goodsabout" name="goodsabout" style="width:700px;height:200px;visibility:hidden;">${(goods.goodsabout)!""}</textarea></td>
		  		<td width="10%"  bgcolor="#FFFFFF">&nbsp;</td>
		  	</tr>
		  	<tr>
		   		<td height="18" bgcolor="#FFFFFF"><span class="STYLE1">上传图片:</span></td>
		   		<td height="18" bgcolor="#FFFFFF">
		   		<div id="thumbnails" style="width:700px;padding:0px;margin-bottom:10px;height:auto;">
		   		<#list accessoryList! as list>
		   		<div id="div_${list.id}" style="width: 100px; float: left; text-align: center;">
					<img src="${saveImagUrl+list.thumbnail}" width='72' height='72' style="margin: 5px; vertical-align: middle; opacity: 1;">
					<br><a href="javascript:delself(${list.id});">删除</a>
					<input type="hidden" value="${list.id}" name="imgs">
				</div>	
		   		</#list>
		   		<div style="clear:both;"></div>
		   		</div>
		   		<div>
					<input type="button" id="uploadButton" value="上传图片" />
				</div>
		   		</td>
		  		<td width="10%"  bgcolor="#FFFFFF">&nbsp;</td>
		  	</tr>
		  	<tr>
		   		<td height="18" bgcolor="#FFFFFF" colspan=2 align="center">
		   			<input type="button" value="保存"  onclick="save()"/>&nbsp;&nbsp;
		   			<input type="button" value="返回" onclick="window.history.back(-1)">
		   		</td>
		   		<td width="10%"  bgcolor="#FFFFFF">&nbsp;</td>
		   	</tr>
		 	</table>
		 	</form>
		 	<td widith="50%" valign="top">
	    			<div align="right" width="95%">
				</div>
				<div id="gridTreeDiv">
				</div>
	    			</td>
	    		</tr>
	    	</table>
        </td>
        <td width="9" background="${base}/res/admin/images/tab_16.gif">	
        </td>
      </tr>
    </table>
	</td>
  	</tr>
  	<tr>
    	<td height="29">
    	<table width="100%" border="0" cellspacing="0" cellpadding="0">
      	<tr>
        <td width="15" height="29"><img src="${base}/res/admin/images/tab_20.gif" width="15" height="29" /></td>
        <td background="${base}/res/admin/images/tab_21.gif">&nbsp;</td>
        <td width="14"><img src="${base}/res/admin/images/tab_22.gif" width="14" height="29" /></td>
      	</tr>
    	</table></td>
  	</tr>
</table>
</body>
</html>
